.import fan.qt.complex 1.0 as Lex
function saveInfo()
{
    gridLayout.readonlyMode = !gridLayout.readonlyMode;

    if (!gridLayout.readonlyMode)
        return


    nav.initializeTask(0, 2, "正在修改用户信息.......")
    nav.openTask("修改信息")
    http.put("/member.json", {id: usinfo.id}, {
                 name: txtNick.text.trim(),
                 mobile: txtMobile.text.trim(),
                 address: txtAddress.text.trim(),
                 identity: txtId.text.trim()
             }, okInfo)

    nav.value++

}


function okInfo(json)
{
    nav.value = nav.maximumValue

    if (json.error) {
        dialog.message(json.error.description)
        return
    }

    usinfo.name = txtNick.text.trim()
    usinfo.mobile = txtMobile.text.trim()
    usinfo.address = txtAddress.text.trim()
    usinfo.mail = txtMail.text.trim()
    usinfo.identity = txtId.text.trim()
    usinfo.address = txtAddress.text.trim()

    dialog.toast("修改成功")
}

function goImage() {
    var path =  Lex.P.toUrl(Lex.P.pictures)
    if(Qt.platform.os == "android") {
        path =  Lex.P.toUrl(Lex.P.camera)
    }
    else if (Qt.platform.os == "windows") {
        path = Lex.P.toUrl(Lex.P.pictures)
    }

    contentArea.push(Qt.resolvedUrl("../template/FileBrowser.qml"), {folder:path, item: imageItem, title: "图片选择" })
}


function commitResult(filePath) {
    var b64 = Lex.A.toBase64(Lex.P.toLocalFile(filePath), Qt.size(120, 120))

    image.source = "data:image/png;base64," + b64
    nav.initializeTask(0, 2, "修改用户信息")

    http.put("/member.json", {id: usinfo.id}, {image:b64}, imageResult)

    nav.value++
}


function imageResult(json) {
    nav.value = nav.maximumValue

    if (json.error) {
        dialog.message(json.error.description)
        return
    }
    usinfo.image = image.source

    dialog.toast("修改成功")
}
